<div class="setting com_width">
    <?php include PROJECT_PATH . 'Application/View/menu.tpl.php';?>
    <div class="menu_head"></div>
    <div class="right">
        <div class="workadd">
            <div class="info">
                <span class="username">经纪人:</span>
                <?php if(Model_User::getLevelID() == 5){?>
                	<span><input id="username" class="text text_middle" type="text" value="<?=Model_User::getUserName()?>" /></span>
                <?php }else{?>
               		<span><?=Model_User::getUserName()?></span>
                <?php }?>
            </div>
            <div class="info">
                <span class="title">是否暂定:</span>
                <select id="sure" class="select text hover flg">
                    <option value="0">否</option>
                    <option value="1">是</option>
                </select>
            </div>
            <div class="info">
                <span class="title">工作日期:</span>
                <input id="starttime" class="time text hover" type="text" value="<?=Model_Common::getFormatTimeYMD()?>" onClick="WdatePicker({readOnly:true,lang:'zh-cn',onpicked:timechange})" />
                <span class="fromto">至</span>
                <input id="endtime" class="time text hover" type="text" value="<?=Model_Common::getFormatTimeYMD()?>" onClick="WdatePicker({readOnly:true,lang:'zh-cn',onpicked:timechange})" />
            </div>
            <div class="info">
                <span class="title">工作时间:</span>
                <select id="starthour" class="select text hover hour" onchange="timechange()">
                    <?php for($hour = 0; $hour <=23; $hour++){?>
                    <option value="<?=$hour?>"><?=$hour?></option>
                    <?php }?>
                </select>
                <select id="startmin" class="select text hover hour" onchange="timechange()">
                    <option value="0">0</option>
                    <option value="15">15</option>
                    <option value="30">30</option>
                    <option value="45">45</option>
                </select>
                <span class="fromto">至</span>
                <select id="endhour" class="select text hover hour" onchange="timechange()">
                    <?php for($hour = 0; $hour <=23; $hour++){?>
                    <option value="<?=$hour?>" <?php if($hour == 23){?>selected="selected" <?php }?>><?=$hour?></option>
                    <?php }?>
                </select>
                <select id="endmin" class="select text hover hour" onchange="timechange()">
                    <option value="0">0</option>
                    <option value="15">15</option>
                    <option value="30">30</option>
                    <option value="45">45</option>
                </select>
            </div>
            <div class="info">
                <span class="title">项目选择:</span>
                <select id="flg" class="select text hover flg" onchange="timechange()">
                    <option value="1">面试</option>
                    <option value="2">工作</option>
                </select>
            </div>
            <div class="info">
                <span class="title long">本公司模特:</span>
                <div id="modelwrapper" class="modelwrapper">
                </div>
            </div>
            <div class="info">
                <span class="title floatleft long1">非本公司资源:</span>
                <textarea id="info" class="multtext"></textarea>
            </div>
            <div class="info nodisplay">
                <span class="title floatleft">特别说明:</span>
                <textarea id="notice" class="multtext">remove</textarea>
            </div>
            <div class="info">
                <span class="title">工作类型:</span>
                <select id="worktype" class="select text hover type">
                    <?php foreach($workType as $key=>$value){?>
                    <option value="<?=$key?>"><?=$value?></option>
                    <?php }?>
                </select>
            </div>
            <div class="info">
                <span class="title">收费单价:</span>
                <input id="perprice" class="text text_middle" type="text" value="0" />
            </div>
            <div class="info nodisplay">
                <span class="title long1">预计小时人数:</span>
                <input id="hour" class="text text_middle" type="text" value="" />
            </div>
            <div class="info">
                <span class="title long1">预计回款日期:</span>
                <input id="prepricetime" class="text hover time" type="text" value="<?=Model_Common::getFormatTimeYMD()?>" onClick="WdatePicker({readOnly:true,lang:'zh-cn'})" />
            </div>
            <div class="info">
                <span class="title">客户名称:</span>
                <input id="companyname" class="text text_middle" type="text" value="" />
            </div>
            <div class="info">
                <span class="username long">客户联系人:</span>
                <input id="customername" class="text text_middle" type="text" value="" />
            </div>
            <div class="info">
                <span class="username">手机号:</span>
                <input id="customertel" class="text text_middle" type="text" value="" />
            </div>
            <div class="info">
                <span class="title long1">其它联系方式:</span>
                <input id="customerothertel" class="text text_middle" type="text" value="" />
            </div>
            <div class="info">
                <span class="title floatleft">客户地址:</span>
                <textarea id="customeraddress" class="multtext"></textarea>
            </div>
            <div class="info">
                <span class="title floatleft">工作地点:</span>
                <textarea id="workaddress" class="multtext"></textarea>
            </div>
            <?php if(Model_User::getLevelID() == 5){?>
            <div class="info">
                <span class="title long1">实际回款金额:</span>
                <input id="price" class="text text_middle" type="text" value="" onkeyup="pricechange();" />
            </div>
            <div class="info">
                <span class="title long1">实际回款日期:</span>
                <input id="pricetime" class="text hover time" type="text" value="" onClick="WdatePicker({readOnly:true,lang:'zh-cn'})" />
            </div>
            <div class="info">
                <span class="title short">成本:</span>
                <input id="cost" class="text text_middle" type="text" value="" onkeyup="pricechange();" />
            </div>
            <div class="info">
                <span class="title short">税款:</span>
                <input id="tax" class="text text_middle" type="text" value="" onkeyup="pricechange();" />
            </div>
            <div class="info">
                <span class="title short">提成:</span>
                <input id="pay" class="text text_middle" type="text" value="" onkeyup="pricechange();" />
            </div>
            <div class="info">
                <span class="title">客户返款:</span>
                <input id="ret" class="text text_middle" type="text" value="" onkeyup="pricechange();" />
            </div>
            <div class="info">
                <span class="title short">利润:</span>
                <input id="profit" class="text text_middle" type="text" value="" />
            </div>
            <?php }?>
            <div class="errmsg" id="errmsg"></div>
            <div class="info">
                <input id="modeladd" class="btn btn_add btn_input" type="button" value="添 加 工 作">
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
	timechange();
    function timechange(){
    	$.ajax({
            url: "http://<?=HOST?>/work/doTimeChange",
            cache: false,
            timeout:10000,
            type: "POST",
            data: {
            	flg:$("#flg").val(),
                starttime:$("#starttime").val(),
                endtime:$("#endtime").val(),
                starthour:$("#starthour").val(),
                endhour:$("#endhour").val(),
                startmin:$("#startmin").val(),
                endmin:$("#endmin").val()
            },
            dataType: "json",
            beforeSend: function() {
            	$("#modelwrapper").html("<span style='margin-top:5px;color:#FF0000'>加载中...</span>");
            },
            success: function(data) {
                    $("#modelwrapper").html(data.errMsg);
            },
            error:function(){
            	$("#modelwrapper").html("<span style='margin-top:5px;color:#FF0000'>加载出错</span>");
            }
          });
    }
    function pricechange()
    {
        total = $("#price").val() - $("#cost").val() - $("#tax").val() - $("#pay").val() - $("#ret").val();
		if(isNaN(total)){
			alert('回款、成本、税款、提成和返款只能是数字');
		}
        $("#profit").val(total);
    }
    $("#modeladd").click(function(){
    	if(!confirm("确定添加吗？"))
    	{
        	return;
    	}
        var modelname = "";
        $(":checkbox:checked").each(function(){
            modelname += "," + $(this).val();
        });

        $("#errmsg").text("");
        $.ajax({
              url: "http://<?=HOST?>/work/doAdd",
              cache: false,
              timeout:10000,
              type: "POST",
              data: {
            	  <?php if(Model_User::getLevelID() == 5){?>
            	  username:$("#username").val(),
            	  <?php }?>
            	  sure:$("#sure").val(),
                  starttime:$("#starttime").val(),
                  endtime:$("#endtime").val(),
                  starthour:$("#starthour").val(),
                  endhour:$("#endhour").val(),
                  startmin:$("#startmin").val(),
                  endmin:$("#endmin").val(),
                  flg:$("#flg").val(),
                  modelid:modelname,
                  info:$("#info").val(),
                  notice:$("#notice").val(),
                  worktype:$("#worktype").val(),
                  perprice:$("#perprice").val(),
                  price:$("#price").val(),
                  pricetime:$("#pricetime").val(),
                  customername:$("#customername").val(),
                  customertel:$("#customertel").val(),
                  customerothertel:$("#customerothertel").val(),
                  customeraddress:$("#customeraddress").val(),
                  workaddress:$("#workaddress").val(),
                  customername:$("#customername").val(),
                  hour:$("#hour").val(),
                  prepricetime:$("#prepricetime").val(),
                  companyname:$("#companyname").val(),
                  cost:$("#cost").val(),
                  tax:$("#tax").val(),
                  pay:$("#pay").val(),
                  ret:$("#ret").val(),
                  profit:$("#profit").val()
                  
              },
              dataType: "json",
              beforeSend: function() {
                  disableHTML(true, '请稍等，处理中……', true);
              },
              success: function(data) {
                  if(data.errCode != 0){
                      disableHTML(true, data.errMsg, false);
                      setTimeout(disableHTML,2000);
                        $("#errmsg").text(data.errMsg);
                  }else{
                      disableHTML(true, '添加成功，跳转中……', true);
                      setTimeout("location.href = 'http://<?=HOST?>/work/list'", 500);
                  }
              },
              error:function(){
                      disableHTML(true, "请求出错，请重试或联系系统管理员", false);
                      setTimeout(disableHTML,2000);
                  }
            });
    });
</script>
